package seller_service

import (
	"errors"
	"go.uber.org/zap"
	"wwt-gin-api/app/global/request"
	"wwt-gin-api/app/global/variable"
	"wwt-gin-api/app/model/api_model"
)

func SellerLogServiceFactory() *SellerLogService {
	return &SellerLogService{}
}

type SellerLogService struct {
}

// AddPlatformBalanceLog
//增加平台余额明细
//@param {*} ctx
//@param {*} money 增加还是扣除的金额
//@param {*} logInfo {source,remark,order_sn}变更来源 1 分佣奖励 3充值 4 提现
//@param {*} transaction
func (receiver *SellerLogService) AddPlatformBalanceLog(money float64, logInfo *request.LogReq) error {
	logType := int8(1) //支出
	if money > 0 {
		logType = 0 //收入
	}
	logRes := api_model.CreateSysPlatformBalanceLogFactory("").Create(&api_model.SysPlatformBalanceLog{
		Money:   money,
		Type:    logType,
		Source:  logInfo.Source,
		Remark:  logInfo.Remark,
		OrderSn: logInfo.OrderSn,
	})
	if logRes.Error != nil {
		variable.ZapLog.Error("AddPlatformBalanceLog错误", zap.Error(logRes.Error))
		return errors.New("日志写入错误")
	}
	return nil
}
